<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <title>京东商城</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      list-style: none;
    }

    .slider {
      height: 340px;
      width: 790px;
      margin: 100px auto;
      position: relative;
    }

    .slider ul li {
      position: absolute;
      display: none;
    }

    .slider ul li:first-child {
      display: block;
    }


    .arrow {
      display: none;
    }

    .slider:hover .arrow {
      display: block;
    }

    .arrow-left,
    .arrow-right {
      font-family: "SimSun", "宋体";
      width: 30px;
      height: 60px;
      background-color: rgba(0, 0, 0, 0.1);
      position: absolute;
      top: 50%;
      margin-top: -30px;
      cursor: pointer;
      text-align: center;
      line-height: 60px;
      color: #fff;
      font-weight: 700;
      font-size: 30px;
    }

    .arrow-left:hover,
    .arrow-right:hover {
      background-color: rgba(0, 0, 0, .5);
    }

    .arrow-left {
      left: 0;
    }

    .arrow-right {
      right: 0;
    }
    .slider ol{
      position: absolute;
      left:100px;
      bottom: 30px;
      width: 240px;
      height: 20px;
    }
    .slider ol li{
      float: left;
      width: 20px;
      height: 20px;
      margin-right: 10px;
      border-radius: 50%;
      background:rgba(255, 255, 255, .5);
      cursor:pointer;
    }
    .slider ol li.cur{
      background-color: #fff;
    }
  </style>
</head>

<body>
  <div class="slider">
    <ul>
      <li><a href="#"><img src="img/jd1.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/jd2.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/jd3.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/jd4.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/jd5.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/jd6.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/jd7.jpg" alt=""></a></li>
      <li><a href="#"><img src="img/jd8.jpg" alt=""></a></li>
    </ul>
    <!--箭头-->
    <div class="arrow">
      <span class="arrow-left">&lt;</span>
      <span class="arrow-right">&gt;</span>
    </div>
    <!-- 下标 -->
    <ol>
      <li class="cur"></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
    </ol>
  </div>

  <script src="lib/jquery-1.12.4.js"></script>
  <script>
    // 
     var $imgindex =  $("ul li");
     var $curindex =  $("ol li");
     var index1 = 0;

    //  自动
    var set = window.setInterval(function () {
      index1++;
      if ( index1 > 7) {
        index1 = 0;
      }
      com(index1);
    },1000)

    // 下标
    $curindex.click(function () {
      var inx = $(this).index();
      $(this).siblings().removeClass("cur");
      $(this).addClass("cur");
      $imgindex.eq(inx).siblings().hide();
      $imgindex.eq(inx).show();
    })

    // 点击左右
    $(".arrow-right").click(function () {
      index1++;
      console.log(index1);
      if ( index1 > 7) {
        index1 = 0;
      }
      com(index1);

    })
    $(".arrow-left").click(function () {
      index1--;
      console.log(index1);
      if ( index1 < 0) {
        index1 = 7;
      }
      com(index1);
    })

    // 悬浮停止
    $(".slider").mouseenter(function () {
      clearInterval(set);
    })
    $(".slider").mouseleave(function () {
      clearInterval(set);
      set =window.setInterval(function () {
      index1++;
      if ( index1 > 7) {
        index1 = 0;
      }
      com(index1);
    },1000);
    
    })
    function com(index1) {
      $imgindex.eq(index1).siblings().hide();
      $imgindex.eq(index1).show();
      $curindex.eq(index1).siblings().removeClass("cur");
      $curindex.eq(index1).addClass("cur");
    }
  </script>
</body>

</html>